//
// Created by lmy on 2024/11/14.
//
#include <iostream>
#include "ClassTest.h"

using namespace std;

class Blank {
    enum {
        age_bits = 4,
        lock_bits = 2,
        biased_lock_bits = 1,

    };
public:
    Blank() {
        age_bits;
        cout << "Blank---" << endl;

    }
};

class Animal {
public:
    int color;
    int age;
    string name;

//    Blank blank;
    Animal() {
        cout << "创建---->Animal:" << "name:" << name.capacity() << endl;
    }

    Animal(const Animal &g) {
        cout << "拷贝/复制函数---->Animal 参数地址:" << &g << endl;
        cout << "拷贝/复制函数---->Animal this地址:" << this << endl;
    }

    Animal &operator=(const Animal &g) {
        cout << "赋值---->Animal" << &color << endl;
    }

    void *operator new(size_t size)   // 参数必须是size_t（unsigned long long），返回值必须是void*。
    {
        cout << "调用了类的重载的new：" << size << "字节。\n";
        void *ptr = malloc(size);        // 申请内存。
        cout << "申请到的内存的地址是：" << ptr << endl;
        return ptr;
    }

    void operator()(string str)    // 向超女表白的函数。
    {
        cout << "重载函数：" << str << endl;
    }

    Animal operator++(int)     // ++后置的重载函数。
    {
        Animal tmp = *this;
        age++;
        cout << "++后置的重载函数 Animal: color," << color << "---" << this << endl;
        return tmp;
    }

    Animal operator++()     // ++前置的重载函数。
    {
        age++;
        cout << "++前置的重载函数 Animal: color," << color << endl;
        return *this;
    }

    ~Animal() {
        cout << "销毁---->Animal: color," << color << endl;
    }

    int getColor() {
        return color;
    }

    int getAge() {
        return age;
    }
};

class Cat : public Animal {
public:
    Cat() {
        cout << "Cat" << endl;
    }

    void getInfo() {
        cout << color << this->getAge() << endl;
    }
};

void getA(Animal a1) {
    cout << "getA:" << &a1 << endl;

}

int main() {

//    Cat cat;
//    cat.getInfo();
//    cout << "main" << sizeof cat << sizeof(Animal) << endl;

//    Animal a, b;
//    cout << "a:" << &a << ",b:" << &b << endl;
//    a.color = 10;
//    b.color = 20;
//    b = a;
//    cout << "a:" << &a << ",b:" << &b << endl;
//    Animal d;
//    cout << "cd:" << &d << endl;
//
//    Animal c = d;
//    cout << "c:" << &c << endl;
//    // getA(c);

//    Animal *e = new Animal();
//    Animal f;
//    f("xxxxx");
//    (*e)("x2");
    Animal g;
    ++g;
//    cout << "g age:" << g.age << endl;
//
//    cout << "g:" << &g << endl;
//
//   Animal h= ++g;
//    cout << "h:" <<h.age  << endl;

//    Animal l = g++;
}
